package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZhOrder;
import com.ruoyi.system.service.IZhOrderService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.service.IZhDeptInfoService;
import com.ruoyi.common.domain.ZhDeptInfo;

/**
 * 订单 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-06-16
 */
@Controller
@RequestMapping("/system/zhOrder")
public class ZhOrderController extends BaseController
{
    private String prefix = "system/zhOrder";

	@Autowired
	private IZhOrderService zhOrderService;

	@Autowired
	private IZhDeptInfoService zhDeptInfoService;

	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhOrder:view")
	@GetMapping()
	public String zhOrder(ZhOrder zhOrder,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhOrder.getParams())));
		return prefix + "/zhOrder";
	}
	
	/**
	 * 查询订单列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhOrder:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ZhOrder zhOrder)
	{
		startPage();
        List<ZhOrder> list = zhOrderService.selectZhOrderList(zhOrder);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出订单列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhOrder:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhOrder zhOrder)
    {
    	List<ZhOrder> list = zhOrderService.selectZhOrderList(zhOrder);
        ExcelUtil<ZhOrder> util = new ExcelUtil<ZhOrder>(ZhOrder.class);
        return util.exportExcel(list, "zhOrder");
    }
	
	/**
	 * 新增订单
	 */
	@RequiresPermissions("system:zhOrder:add")
	@DataScope(tableAlias = "l")
	@GetMapping("/add")
	public String add(ZhOrder zhOrder,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhOrder.getParams())));
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存订单
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhOrder:add")
	@Log(title = "订单", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ZhOrder zhOrder)
	{		
		return toAjax(zhOrderService.insertZhOrder(zhOrder));
	}

	/**
	 * 修改订单
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhOrder:edit")
	@GetMapping("/edit/{id}")
	public String edit(ZhOrder zhOrder,@PathVariable("id") Integer id, ModelMap mmap)
	{
		ZhOrder result = zhOrderService.selectZhOrderById(id);
		mmap.put("zhOrder", result);
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhOrder.getParams())));
		return prefix + "/edit";
	}
	
	/**
	 * 修改保存订单
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhOrder:edit")
	@Log(title = "订单", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ZhOrder zhOrder)
	{		
		return toAjax(zhOrderService.updateZhOrder(zhOrder));
	}
	
	/**
	 * 删除订单
	 */
	@RequiresPermissions("system:zhOrder:remove")
	@Log(title = "订单", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(ZhOrder zhOrder,String ids)
	{		
		return toAjax(zhOrderService.deleteZhOrderByIds(ids));
	}

	@RequiresPermissions("system:zhOrder:setDelivery")
	@Log(title = "订单", businessType = BusinessType.UPDATE)
	@PutMapping("/delivery/{id}")
	@DataScope(tableAlias = "l")
	@ResponseBody
	public AjaxResult setDelivery(ZhOrder zhOrder,@PathVariable("id")int id){
		zhOrderService.updateDelivery(id);
		return AjaxResult.success("");
	}
}
